package com.app.controller;

import com.app.service.*;
import com.app.util.Result;
import com.app.vo.AdminHomePageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/adminHomePageController")
@Api(tags = "admin首页接口")
public class AdminHomePageController {

    @Autowired
    private IUserService userService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IPaymentRecordsLogService paymentRecordsLogService;
    @Autowired
    private IGasDetailsService gasDetailsService;

    @ApiOperation(value = "顶部数据查询")
    @GetMapping("/top")
    public Result<AdminHomePageVo> top() {
        AdminHomePageVo adminHomePageVo = new AdminHomePageVo();
        //用户注册数量
        Integer registrationsNum = userService.count();
        //设备数量
        Integer devicesNum = gasDetailsService.count();
        //用户反馈数量
        Integer feedbackNum = companyService.count();
        //缴费金额
        BigDecimal paymentAmount = paymentRecordsLogService.sumMoney();
        //异常设备数量
        Integer abnormalDevicesNum = 4;//todo 异常设备数量
        //欠费用户数
        Integer arrearsUserNum  = gasDetailsService.countArrearsUserNum();
        adminHomePageVo.setRegistrationsNum(registrationsNum);
        adminHomePageVo.setDevicesNum(devicesNum);
        adminHomePageVo.setFeedbackNum(feedbackNum);
        adminHomePageVo.setPaymentAmount(paymentAmount);
        adminHomePageVo.setAbnormalDevicesNum(abnormalDevicesNum);
        adminHomePageVo.setArrearsUserNum(arrearsUserNum);
        return Result.success(adminHomePageVo);
    }


    @ApiOperation(value = "用户增长趋势")
    @GetMapping("/userGrowthTrend")
    public Result<AdminHomePageVo> userGrowthTrend() {
        return userService.userCrowthTrend();
    }


    @ApiOperation(value = "30天缴费金额")
    @GetMapping("/paymentAmount")
    public Result<AdminHomePageVo> paymentAmount() {
        return paymentRecordsLogService.paymentAmount();
    }



}
